package Q2;

import java.util.Scanner;

public class Main {

    public static int ret = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int t = scanner.nextInt();
        while (t > 0) {
            t--;
            int num = scanner.nextInt();
            dfs(num - 1, 1, 1);
            System.out.println(ret);
            ret = Integer.MAX_VALUE;
        }
    }

    public static void dfs(int num, int preSub, int count) {

        if (num < 0) {
            return;
        }

        if (num == 0) {
            ret = Math.min(ret, count);
            return;
        }

        //与上一次减的数字相同
        dfs(num - preSub, preSub, count + 1);

        //是上一次减的数字两倍
        dfs(num - 2 * preSub, preSub * 2, count + 1);
    }
}
